package com.kaifamiao.entity;

import org.tinylog.Logger;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

// 注意:这种监听器不需要显式部署
public class User implements HttpSessionBindingListener {

    private Integer id;
    private String username;
    private String password;
    private String salt;

    // 当前类的实例作为属性值绑定到会话对象时调用该方法
    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        HttpSession session = event.getSession();
        Logger.trace("将{}绑定到会话({})", this, session.getId());
    }

    // 将当前类的实例对应的属性从会话对象中移除时调用该方法
    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        HttpSession session = event.getSession();
        Logger.trace("将{}与会话({})解除绑定", this, session.getId());
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }
}
